//DEMO.JS  部分参数外部传入
const style = {
  canvas_box: {
    width: 640,
    height: 1008,
    borderRadius: 0,
    backgroundColor: '#fff',
    padding: 0,
    position: 'relative'
  },
  pop_img: {
    width: 640,
    height: 1008,
    borderRadius: 0,
    overflow: "hidden",
    display: "block"
  },
  pop_h4: {
    lineHeight: 20,
    paddingTop: 10,
    width: 300,
    fontSize: 14,
    color: "#666",
    paddingBottom: 10,
    position: "absolute",
    left: 10,
    top: 10,
  },
}
const poster = (shop) => {
  if (shop) {
    let wxml;
    if (shop.poster_data) {
      let ImgView = ``;
      shop.poster_data.map((item, ind) => {
        if (item.color) {
          let txt;
          // let textWidth = item.size * String(item.src).length;
          // let boxWidth = item.width;
          // // 直接计算字体是否超出盒子一半再进行省略
          // if (textWidth > (boxWidth * 2)) {
          //   let isheightTxt = (item.width / item.size).toFixed(0);
          //   let height_row = parseInt(item.height / item.size);
          //   console.log(textWidth, boxWidth * 2, isheightTxt, height_row)
          //   txt = item.src.slice(0, (isheightTxt * height_row) - 1) + '...';
          // } else {
            txt = item.src
          // }
          if (item.type == "member_price") {
            txt = '会员价:￥' + item.src
          }
          if (item.type == "market_price") {
            txt = '原价:￥' + item.src
          }
          if (item.type == "price") {
            txt = '现价:￥' + item.src
          }
          ImgView += `<view class="pop_QRcode${ind}"><text class="pop_h4_text${ind}">${txt}</text></view>`
          style[`pop_QRcode${ind}`] = {
            "lineHeight": item.size, //最大就20,手动设置多都会导致文字没有渲染出来
            "height": item.height,
            "width": item.width,
            "fontSize": item.size,
            "color": item.color,
            "position": "absolute",
            "left": item.left,
            "top": item.top,
          }
          style[`pop_h4_text${ind}`] = {
            "height": item.height,
            "width": item.width,
          }
        } else if (item.src != "") {
          ImgView += `<image class="pop_QRcode${ind}" src="${item.src}" />`
          style[`pop_QRcode${ind}`] = {
            'width': item.width,
            'height': item.height,
            "position": "absolute",
            "left": item.left,
            "top": item.top
          }
        }
      })
      wxml =
        `<view class="canvas_box">
        ${shop.background?`<image class="pop_img" mode="widthFix" src="${shop.background.src}" />`:''}
        ${ImgView}
      </view>`
    }
    if (shop)
      return {
        wxml,
        style
      };
  }
}
module.exports = {
  poster,
}